#!/usr/bin/python3
#################################################################################
#    WCH-Link 驱动                                                              #
#    Copyright (C) 2021 Xu Ruijun                                               #
#                                                                               #
#    This program is free software; you can redistribute it and/or modify       #
#    it under the terms of the GNU General Public License as published by       #
#    the Free Software Foundation; either version 2 of the License, or          #
#    any later version.                                                         #
#                                                                               #
#    This program is distributed in the hope that it will be useful,            #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of             #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
#    GNU General Public License for more details.                               #
#                                                                               #
#    You should have received a copy of the GNU General Public License along    #
#    with this program; if not, write to the Free Software Foundation, Inc.,    #
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                #
#################################################################################

import usb.core
import usb.util
import time

dev = usb.core.find(idVendor=0x1a86, idProduct=0x8010)
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep_w1 = usb.util.find_descriptor(intf, custom_match = lambda e: e.bEndpointAddress == 0x01)
ep_r1 = usb.util.find_descriptor(intf, custom_match = lambda e: e.bEndpointAddress == 0x81)
ep_w2 = usb.util.find_descriptor(intf, custom_match = lambda e: e.bEndpointAddress == 0x02)
ep_r2 = usb.util.find_descriptor(intf, custom_match = lambda e: e.bEndpointAddress == 0x82)

#TODO: 使用class封装
